package com.ce.utils;

import java.util.Stack;

public class DownloadRes implements Runnable {
	Stack<String> stock;
	String name;
	int empty = 0;
	public DownloadRes(Stack<String> stock, String name) {
		this.stock = stock;
		this.name = name;
	}
	public void run() {
		while (true) {
			String url = "";
			if(!stock.isEmpty()) {
				url = stock.pop();
				if(url.contains(".swf"))
					FileResDownload.downloadSwf(url);
				else
					FileResDownload.downloadPic(url);
				System.out.println(name+"-Consume---stack size:"+stock.size()+">>"+url);
			} else {
				empty++;
				if(empty>10) {
					System.out.println(name+"====================================");
					for (String eurl : FileResDownload.errorList) {
						System.out.println(eurl);
					}
					System.out.println(name+"====================================");
					break;
				}
			}
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
